/*
 * @lc app=leetcode id=14 lang=cpp
 *
 * [14] Longest Common Prefix
 */
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        string ret;

        if (strs.size() < 1) {
            return ret;
        }

        sort(strs.begin(), strs.end());

        bool done = false;
        int len = strs[0].size();
        for (int i=0; i<len; i++) {
            char c = strs[0][i];
            for (int j=1; j<strs.size(); j++) {
                if (strs[j][i] != c) {
                    done = true;
                    break;
                }
            }

            if (done) {
                break;
            } else {
                ret += c;
            }
        }

        return ret;
        
    }
};

